-
-
Notifications
You must be signed in to change notification settings - Fork 578
fix(form-core): π File input field - Picking a different file does not trigger rerender (deep equality issue with File/Blob objects) #1939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
packages/form-core/src/utils.ts
Outdated
| * @private | ||
| */ | ||
| export function setBy(obj: any, _path: any, updater: Updater<any>) { | ||
| const isFile = updater instanceof File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React Native does not have File defined and will throw a ReferenceError. You cannot implement the fix this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Truly. Good catch, thanks!
|
View your CI Pipeline Execution β for commit df74f02
βοΈ Nx Cloud last updated this comment at |
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1939 +/- ##
==========================================
- Coverage 90.35% 89.25% -1.11%
==========================================
Files 38 48 +10
Lines 1752 1954 +202
Branches 444 498 +54
==========================================
+ Hits 1583 1744 +161
- Misses 149 189 +40
- Partials 20 21 +1 β View full report in Codecov by Sentry. π New features to boost your workflow:
|
β¦trigger-rerender' of github-personal.com:joaoGabriel55/form into fix/file-input-field-picking-a-different-file-does-not-trigger-rerender
LeCarbonator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the previous comment hasn't been addressed between the previous review and this review request.
The actual required changes don't look that bad, though. Perhaps I'll have some time to help out later this week with that.
| if (!path.length) { | ||
| return functionalUpdate(updater, parent) | ||
| return functionalUpdate( | ||
| isFile(updater) ? { file: updater, uuid: uuid() } : updater, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't type safe. This wrongly asserts File field values as { file: File | (oldFile: File) => File, uuid: string } instead of
- actually running the updater
- Preserving the expected field value's structure
| } | ||
|
|
||
| export function evaluate<T>(objA: T, objB: T) { | ||
| if (objA instanceof File && objB instanceof File) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the previous comment wasn't addressed, despite the request for another review. This will throw ReferenceErrors in environments where File is not present (such as React Native).
| const firstFile = new File(['first'], 'first.png', { type: 'image/png' }) | ||
| form.setFieldValue('avatar', firstFile) | ||
|
|
||
| const firstValue = form.state.values.avatar as { file: File; uuid: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These type assertions are a huge problem. It cannot stay.
Luckily, as long as evaluate properly handles File types, this whole uuid trickery won't be needed. Just make sure to add unit tests for a File comparison with evaluate. I believe the existing tests can be found in utils.spec.ts.
Issue: #1932
π― Changes
β Checklist
pnpm test:pr.π Release Impact